﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TuanAnhPersonalWeb.Models;

namespace TuanAnhPersonalWeb.Areas.Admin.Controllers
{
     [Authorize(Roles = "admin,project")]
    public class FixCodeController : Controller
    {
        private TuanAnhEntities db = new TuanAnhEntities();

        //
        // GET: /Admin/FixCode/

        public int? currentCode()
        {
            int? cr = db.TUANANH__PROJECT.Max(e => e.PROJECT_ID);
            return cr;
        }
        public FixModel getcode()
        {
            FixModel model = new FixModel();
            TUANANH__CODE data = db.TUANANH__CODE.Where(e => e.TYPE == "PROJECT").Single();
            model.currentCode = currentCode();
            model.tableCode = data.CODE;
            return model;

        }
        public ActionResult Index()
        {
            var model = getcode();
            return View(model);
        }
        public ActionResult Fixcode()
        {
            TUANANH__CODE data = db.TUANANH__CODE.Where(e => e.TYPE == "PROJECT").Single();
            int? fix=currentCode();
            data.CODE = fix;
            db.SaveChanges();
            return View("UnlockSuccess");
       
        }

        //
      
    }
}